﻿using ASmile.CodeFactory.DBModel;
using ASmile.Helpers;
using ASmile.ORM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASmile.CodeFactory.DaBLL.Builder
{
    class BuilderFactory
    {        
        public static IBuilder Create(TConfig config, bool configRemark = false)
        {
            if (!EnumHelper.StringToEnum<EmDbType>(config.DBType, out EmDbType t))
            {
                throw new NotSupportedException("错误的数据库类型");
            }
            IBuilder builder;
            switch (t)
            {
                case EmDbType.SQLServer:
                    builder = new BuilderSqlServer(config);
                    break;
                case EmDbType.SQLite:
                    builder = new BuilderSQLite(config);
                    break;
                case EmDbType.Oracle:
                    builder = new BuilderOracle(config);
                    break;
                case EmDbType.MySQL:
                    builder = new BuilderMySql(config);
                    break;
                default:
                    throw new NotSupportedException("不支持的数据库类型");
            }
            if (!configRemark)
            {
                builder.SetConfigRemark();
            }
            return builder;
        }
    }
}